﻿using System;
using System.Collections.Generic;
using System.Text;
using QuanLyThuoc.DAL;
using System.Data;
namespace QuanLyThuoc.BUS
{
    class PhieuNhapBUS
    {
        private static readonly PhieuNhapDAL phieu = new PhieuNhapDAL();
        public static DataTable SelectAll_PhieuNhap()
        {
            return phieu.SelectAll_PhieuNhap();

        }
        public static DataTable SelectTamMax_PhieuNhap()
        {
            return phieu.SelectTamMax_PhieuNhap();
        }
        public static DataTable LayIDSoPhieuNhap()
        {
            string sql = @"select IDPN  from tbPhieuNhap order by IDPN";
            return phieu.GetDataTable(sql);
        }
        public static DataTable DemSttThuocNhap()
        {
            string sql = @"select Max(Stt)as Stt from tbThuocNhap order by Stt";
           return phieu.GetDataTable(sql);
        }
        public static DataTable KiemTraIDPhieuNhap(int ID)
        {
            string sql = @"select IDPN from tbThuocNhap where IDPN='" + ID + "' and IDPN is not null";
            return phieu.GetDataTable(sql);
        }
        public static DataTable SelectIDPhieuNhap(string IdPhieuNhap)
        {
            return phieu.SelectIDPhieuNhap(IdPhieuNhap);
        }
        public static void InsertNhapThuocs(string IDPN,string IDCT, int IDThuoc, string TenThuoc, string DVtMua, string Dvt, decimal HeSoQD, int SL_N, int GiaNhap, int ThanhTien, DateTime NgaySX, DateTime HanDate)
        {
            string sql = @"insert into tbThuocNhap values('" + IDPN + "','" + IDThuoc + "','" + TenThuoc + "','" + DVtMua + "','" + Dvt + "','" + HeSoQD + "','" + SL_N + "','" + GiaNhap + "','" + ThanhTien + "','" + NgaySX + "','" + HanDate + "','" + IDCT + "')";
            phieu.ExcuteNonQuery(sql);
        }
        public static void UpdateNhapThuoc(string IDPN, string IDCT, string TenThuoc, int IDThuoc, string DVtMua, string Dvt, decimal HeSoQD, int SL_N, int GiaNhap, int ThanhTien, DateTime NgaySX, DateTime HanDate)
        {
            string sql = @"Update  tbThuocNhap set IDPN='" + IDPN + "',TenThuoc='" + TenThuoc + "',IDThuoc='" + IDThuoc + "',DvtMua='" + DVtMua + "',Dvt='" + Dvt + "',HeSoQD='" + HeSoQD + "',SL_N='" + SL_N + "',GiaNhap='" + GiaNhap + "',ThanhTien='" + ThanhTien + "',NgayXuat='" + NgaySX + "',HanDate='" + HanDate + "'where IDCT='" + IDCT + "'";
            phieu.ExcuteNonQuery(sql);
        }
        public static void UpdatePhieuNhap(string IDPN, DateTime NgayNhap, int IDNCC, string GhiChu)
        {
            string sql = @"Update  tbThuocNhap set NgayNhap='" + NgayNhap + "',IDNCC='" + IDNCC + "',GhiChu='" + GhiChu + "'where IDPN='"+IDPN+"'";
            phieu.ExcuteNonQuery(sql);
        }
        public static int InsertPhieuNhap(string IDPN, DateTime NgayNhap, int IdNhaCC, string GhiChu)
        {
            return phieu.InsertPhieuNhap(IDPN, NgayNhap, IdNhaCC, GhiChu);
        }
        public static int UpdatePhieuNhaps(string IDPN, DateTime NgayNhap, int IdNhaCC, string GhiChu)
        {
            return phieu.UpdatePhieuNhap(IDPN, NgayNhap, IdNhaCC, GhiChu);
        }
        public static int DeletePhieuNhap(string IDPN)
        {
            return phieu.DeletePhieuNhap(IDPN);
        }
    }
}
